<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head> 
    <title>微信支付</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
	<script type="text/javascript">
		 var msg = "$!errMsg";
		 var appId = "$!appId";
		 var timeStamp = "$!timeStamp";
		 var nonceStr = "$!nonceStr";
		 var pkg = "$!package";
		 var signType = "$!signType";
		 var paySign = "$!sign";
		 var orderId = "$!orderId";
		 function f_pay(){
			   if(msg == null || msg == ""){
				   WeixinJSBridge.invoke(
					       'getBrandWCPayRequest', {
					           "appId": appId,     //公众号名称，由商户传入     
					           "timeStamp": timeStamp,         //时间戳，自1970年以来的秒数     
					           "nonceStr": nonceStr, //随机串     
					           "package": pkg,     
					           "signType" : signType,         //微信签名方式：     
					           "paySign": paySign //微信签名 
					       },
					       function(res){     
					           if(res.err_msg == "get_brand_wcpay_request:ok" ) {
					        	   location.href = "$!rc.contextPath/paySuccess?orderId=" + orderId;
					           }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。 
					       }
					   ); 
			   }else{
				   alert(msg);
				   window.history.back();
			   }
			 
			}
		 
		if (typeof WeixinJSBridge == "undefined"){
		   if( document.addEventListener ){
		       document.addEventListener('WeixinJSBridgeReady', f_pay, false);
		   }else if (document.attachEvent){
		       document.attachEvent('WeixinJSBridgeReady', f_pay); 
		       document.attachEvent('onWeixinJSBridgeReady', f_pay);
		   }
		   
		   if(msg){
			   alert(msg);
			   window.history.back(-1);
		   }
		   
		   //location.href = "$!rc.contextPath/paySuccess?orderId=" + orderId;
		}else{
			if(msg){
			   alert(msg);
			   window.history.back(-1);
		   }
			
			f_pay();
			
			//location.href = "$!rc.contextPath/paySuccess?orderId=" + orderId;
		}
	</script>
</body>

</html>
